<?php
/* CAPTCHA Validation projects */
define ( VERSION, '1.0a' );

/* CHAPTA BUMP CLASS */

class Captcha {

	/* VARIABLES */
	var $var01 = 64;
	var $var02 = 90;
	var $var03 = 0x66; // Red
	var $var04 = 0x66; // Green
	var $var05 = 0x00; // Blue
	var $var06 = 130;
	var $var07 = true;
	var $var08 = array ( );
	var $var09 = array ( );
	var $var10 = array ( );
	var $var11 = array ( );
	var $var12 = array ( );
	var $var13;
	var $var14;
	var $var15;
	var $var16;
	var $var17;
	var $var18;
	
	/* MAIN CLASS CONSTRUCTOR */
	function Captcha ( $text, $font, $color )
	{
		$var0 = $font;
		$var4 = HexDec ( $color );
		$this->var03 = floor ( $var4 / pow ( 256, 2 ) );
		$this->var04 = floor ( ( $var4 % pow ( 256, 2 ) ) / pow ( 256, 1 ) );
		$this->var05 = floor ( ( ( $var4 % pow ( 256, 2 ) ) % pow ( 256, 1 ) ) / pow ( 256, 0 ) );
		$var1 = array ( );
		$var1 = imageTTFBbox ( 22, 0, $var0, $text );
		$this->var13 = imageCreateTrueColor ( $var1[4] + 15, abs( $var1[5] ) + 15 );
		$var2 = ImageColorAllocate( $this->var13,    0,    0,    0 );
		$var3 = ImageColorAllocate( $this->var13,  192,  192,  192 );
		imageFill( $this->var13, 0, 0, $var2 );
		imagettftext( $this->var13, 22, 0, 7, abs( $var1[5] ) + 6, $var3, $var0, $text);
    	$this->var14 = imageSX ( $this->var13 );
    	$this->var15 = imageSY ( $this->var13 );
    	for ( $y = 0; $y < $this->var15; $y++ )
    		for ( $x = 0; $x < $this->var14; $x++ )
    		{
    			$p = imageColorsForIndex ( $this->var13, imageColorAt ( $this->var13, $x, $y ) );
    			$this->var17[$x][$y] = $p['red'] + $p['green'] + $p['blue'];
    		}
    	imageDestroy ( $this->var13 );
    	$this->var13 = imageCreateTrueColor ( $this->var14, $this->var15 );
		Captcha::funcs01 ( );
		Captcha::funcs02 ( );
		Captcha::funcs03 ( );
	}
	
	/* FUNCTION 01 */
	function funcs01 ( )
	{
    	for ( $x = 0; $x < $this->var14; $x++ )
    		for ( $y = 0; $y < $this->var15; $y++ )
    		{
    			$var0 = 0;
				$var0 += $this->var17[$x][$y];
				$var0 += $this->var17[( $x + 1 ) % $this->var14][$y];
				$var0 += $this->var17[( $x + $this->var14 - 1) % $this->var14][$y];
				$var0 += $this->var17[$x][( $y + 1 ) % $this->var15];
				$var0 += $this->var17[$x][( $y + $this->var15 - 1 ) % $this->var15];
				$var0 += $this->var17[( $x + 1 ) % $this->var14][( $y + 1 ) % $this->var15];
				$var0 += $this->var17[( $x + $this->var14 - 1) % $this->var14][( $y + $this->h - 1 ) % $this->var15];
				$var0 += $this->var17[( $x + $this->var14 - 1) % $this->var14][( $y + 1 ) % $this->var15];
				$var0 += $this->var17[( $x + 1 ) % $this->var14][( $y + $this->var15 - 1) % $this->var15];
				$var0 /= 9;
				$var1[$x][$y] = ( ( float ) $var0 / 3 * ( float ) $this->var01 / 255);
			}
    	for ( $x = 1; $x < $this->var14 - 1; $x++ )
    		for ( $y = 1; $y < $this->var15 - 1; $y++ )
    		{
				$this->var11[$x][$y] = ( $var1[$x + 1][$y] - $var1[$x - 1][$y] );
				$this->var12[$x][$y] = ( $var1[$x][$y + 1] - $var1[$x][$y - 1] );
			}
	}
	
	/* FUNCTION 02 */
	function funcs02 ( )
	{
		for ( $i = 0; $i < ( 255 - $this->var02 ); $i++)
		{
			$r = ( int ) ( $this->var03 * $i / (255 - $this->var02 ) );
			$g = ( int ) ( $this->var04 * $i / (255 - $this->var02 ) );
			$b = ( int ) ( $this->var05 * $i / (255 - $this->var02 ) );
			$this->var09[$i] = array ( $r, $g, $b );
		}
		for ( $i = ( 255 - $this->var02 );  $i < 256; $i++ )
		{
			$r = ( int ) ( $this->var03 + ( 255 - $this->var03 ) * ( $i + $this->var02 - 255 ) / $this->var02 );
			$g = ( int ) ( $this->var04 + ( 255 - $this->var04 ) * ( $i + $this->var02 - 255 ) / $this->var02 );
			$b = ( int ) ( $this->var05 + ( 255 - $this->var05 ) * ( $i + $this->var02 - 255 ) / $this->var02 );
			$this->var09[$i] = array ( $r, $g, $b );
		}
	}
	
	/* FUNCTION 03 */
	function funcs03 ( )
	{
		$this->var16 = $this->var06;
		for ( $y = 0; $y < $this->var06; $y ++ )
		{
			for ($x = 0; $x < $this->var06; $x++ )
			{
				$var0 = ( (float) $x ) / $this->var16;
				$var1 = ( (float) $y ) / $this->var16;
				$var2 = ( float ) ( 1 - sqrt ( $var0 * $var0 + $var1 * $var1 ) );
				if ( $var2 < 0 ) $var2 = 0;
				$this->var10[$x][$y] = ( int ) ( $var2 * 0xff );
			}
		}
	}
	
	/* CAPTCHA FRAME */
	function Frame ( $Lx, $Ly )
	{
		$this->var16 = $this->var06 - 1;
		for ( $y = 0; $y < $this->var15; $y++ )
		{
			$yoffset = $y * $this->var14;
			for ( $x = 0; $x < $this->var14; $x++ )
			{
				$var0 = ( int ) abs ( $this->var11[$x][$y] - $x + $Lx);
				$var1 = ( int ) abs ( $this->var12[$x][$y] - $y + $Ly);

				if ( $var0 > $this->var16 ) $var0 = $this->var16;
				if ( $var1 > $this->var16 ) $var1 = $this->var16;

				if ( $this->var07 )
				{
					$this->var08[$x + $yoffset] = ( $this->var10[$var0][$var1] >> 1 ) + ( $this->var08[$x + $yoffset] >> 1 );
					imageSetPixel ( $this->var13, $x, $y, imageColorAllocate ( $this->var13, $this->var09[$this->var08[$x + $yoffset]][0], $this->var09[$this->var08[$x + $yoffset]][1], $this->var09[$this->var08[$x + $yoffset]][2] ) );
				}
				else
				{
					$this->var08[$x + $yoffset] = $this->var10[$var0][$var1];
					imageSetPixel ( $this->var13, $x, $y, imageColorAllocate ( $this->var13, $this->var09[$this->var08[$x + $yoffset]][0], $this->var09[$this->var08[$x + $yoffset]][1], $this->var09[$this->var08[$x + $yoffset]][2] ) );
				}
			}
		}
		ob_start ( ); imageGif ( $this->var13 ); $var2 = ob_get_contents ( ); ob_end_clean ( ); return $var2;
	}
}
?>
